package com.huika.dealontop.control.shops.holder;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.huika.dealontop.R;
import com.huika.dealontop.control.base.extend.BaseViewHolder;
import com.huika.dealontop.support.domain.OtherProductItemBean;
import com.huika.dealontop.utils.ImageLoaderHelper;
import com.huika.dealontop.utils.UIUtils;
import com.huika.huikalib.utils.MoneyShowTool;

/**
 * Author: Victor Wu <br/>
 * Email: victor-wu*foxmail.com <br/>
 * Time: 2015/11/23 20:48 <br/>
 * Description: 其他商品 条目
 */
public class OtherProductItemHolder extends BaseViewHolder<OtherProductItemBean> {
    private ImageView mIvIcon;
    private TextView mTvName;
    private TextView mTvPrice;
    private TextView mTvDiscount;
    private TextView mTvProductRate;
    private RatingBar mRbProductRate;

    public OtherProductItemHolder(Context context) {
        super(context);
    }

    @Override
    protected View initView() {
        View view = View.inflate(UIUtils.getContext(), R.layout.item_other_project_detail, null);
        mIvIcon = (ImageView) view.findViewById(R.id.project_iv_icon);
        mTvName = (TextView) view.findViewById(R.id.project_tv_name);
        mTvPrice = (TextView) view.findViewById(R.id.project_tv_price);
        mTvDiscount = (TextView) view.findViewById(R.id.project_tv_zhekounum);
        mTvProductRate = (TextView) view.findViewById(R.id.project_tv_pingfennum);
        mRbProductRate = (RatingBar) view.findViewById(R.id.project_rb_pingfen);
        return view;
    }

    @Override
    protected void refreshView(OtherProductItemBean data) {
        ImageLoaderHelper.displayImage(data.getProductPicUrl(), mIvIcon, R.mipmap.morenpic);
        mTvName.setText(data.getProductName());
        //mTvProductJunLi.setText(DistanceUtils.formatMeter(product.getProductRate()));
        mTvPrice.setText(MoneyShowTool.nolastDF(data.getSalesPrice()));
        if(data.getDiscount() > 0){
            mTvDiscount.setText(MoneyShowTool.nolastDF(data.getDiscount(), false) + "% Off");
        }
        if(data.getProductRate() == 0){
            data.setProductRate(5);
        }
        mRbProductRate.setRating(Float.parseFloat(MoneyShowTool.formatOne(data.getProductRate())));
        mTvProductRate.setText(MoneyShowTool.formatOne(data.getProductRate()));
    }
}
